/*** 
 * @ ****************************************** 
 * @Editors: yangyifan yangyf@mw-robot.com
 * @Date: 2025-03-13 18:23:36
 * @LastEditTime: 2025-04-30 16:36:51
 * @Description: 
 * @ ****************************************** 
 */

#pragma once

#include "calibrator.h"

class IntrinsicCalibrator : public Calibrator{
public:
    IntrinsicCalibrator(const IntrinsicConfig& config);
    
    bool run();
private:
    bool processFrame(const cv::Mat& frame);
    bool loadResults(const std::string& path);
    
    bool detectChessboard(const cv::Mat& frame, std::vector<cv::Point2f>& corners) const;
    void generateObjectPoints();
    bool saveResults(const std::string& path);
    bool saveUndistortedImages(std::string output_dir);
private:
    ConfigInfo& configInfo_;
    IntrinsicConfig config_;
    std::vector<std::vector<cv::Point3f>> object_points_; // 标定板3D点集
    std::vector<std::vector<cv::Point2f>> image_points_; // 图像角点坐标集
    cv::Mat camera_intr_matrix_; // 相机内参矩阵
    cv::Mat dist_coeffs_; // 畸变系数
    cv::Size image_size_; // 图像尺寸
    double reproj_error_ = 0.0; // 标定误差
    std::vector<cv::String> image_files;
    std::string pattern_ = "/home/mw/MyWork/calibration/data/img/";
    std::string output_dir_ = "/home/mw/MyWork/calibration/data/undistorted/";
    std::string camera_intr_params_path_ = "/home/mw/MyWork/calibration/data/camera_intr_params.yaml";
};
